<?php
/**
 * @author Eugenio Fage
 * http://eugeniofage.wordpress.com/
 * http://code.google.com/p/monky/
 * 
 */
class Clon extends AppModel {
	var $name = 'Clon';
	
	var $validate = array(
		'from' => array(
			'numeric' => array(
				'rule' => array('numeric')
			),
		),
		'to' => array(
			'numeric' => array(
				'rule' => array('numeric')
			),
		),
		'ip' => array(
			'notempty' => array(
				'rule' => array('notempty')
			),
		),
	);
	
	function getClones($user_id,$hours=24) {
		// Return the count of cookies clones that voted before a given link, comment, note
		$dateCondition='Clon.created > date_sub(now(), interval '.$hours.' hour)';
						
		// This as from 
		$a = $this->find('list',array(
			'fields'=>array('Clon.to'),
			'conditions'=>array(
				'Clon.from' => $user_id,
				$dateCondition
			),'recursive'=>-1			
		));
				
		// This as to
		$b = $this->find('list',array(
			'fields'=>array('Clon.from'),
			'conditions'=>array(
				'Clon.to' => $user_id,
				$dateCondition
			),'recursive'=>-1
		));
		
		return array_unique(am($a, $b));
	}
	
	
}
?>